//
//  HJPre-appointmentController.m
//  Keping
//
//  Created by a on 2017/8/28.
//  Copyright © 2017年 柯平. All rights reserved.
//

#import "HJPre-appointmentController.h"
#import "HJVisitFriendController.h"
#import "HJInviteGuestController.h"
#import "HJContractorSeasonPassController.h"
#import "HJAppointmentsController.h"

#import "HJPre_appointmentCell.h"

@interface HJPre_appointmentController ()<UITableViewDelegate,UITableViewDataSource>
/**
 tableView
 */
@property(nonatomic,weak)UITableView*tableView;
/**
 数据源
 */
@property(nonatomic,strong)NSArray*dataAry;
@property(nonatomic, copy) NSArray *itemAry;
@end

@implementation HJPre_appointmentController
-(NSArray *)dataAry
{
    if (!_dataAry) {
        _dataAry=@[@"invite_guest",@"CS_pass",@"appointments"];//@"visit_friend",
    }
    return _dataAry;
}

- (NSArray *)itemAry {
    if (!_itemAry) {
        _itemAry = @[@"Invite Guests",@"Contractor/Season Pass",@"Appointments"];//@"Visit Friend",
    }
    return _itemAry;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUI];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushAppOintmentsForVisit) name:@"KPushAppOintmentsForVisit" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushAppOintmentsForGuest) name:@"KPushAppOintmentsForGuest" object:nil];
}
-(void)setUI
{
    self.navigationItem.title=@"Pre-appointment";
    UITableView*tableView=[[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    tableView.delegate=self;
    tableView.dataSource=self;
    tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:tableView];
    self.tableView=tableView;
    
}
#pragma mark --UITableViewDelegate

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataAry.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HJPre_appointmentCell*cell=[HJPre_appointmentCell cellWithTableView:tableView];
    cell.imgStr = self.dataAry[indexPath.row];
    cell.titleLabel.text = self.itemAry[indexPath.row];
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return K_FactorH(150);
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
//        case 0:
//        {
//            HJVisitFriendController*vc=[HJVisitFriendController new];
//            [self.navigationController pushViewController:vc animated:YES];
//        }
//            break;
        case 0:
        {
            HJInviteGuestController*vc=[HJInviteGuestController new];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1:
        {
            WEAKSELF
            HJContractorSeasonPassController*vc=[HJContractorSeasonPassController new];
            vc.contractiorBlock = ^(BOOL isSuccess) {
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    HJAppointmentsController*vc=[[HJAppointmentsController alloc] initWithIndex:1];
                    [weakSelf.navigationController pushViewController:vc animated:YES];
                });
            };
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 2:
        {
            HJAppointmentsController*vc=[HJAppointmentsController new];
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        default:
            break;
    }
}


- (void)pushAppOintmentsForGuest {
    WEAKSELF
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        HJAppointmentsController*vc=[[HJAppointmentsController alloc] initWithIndex:1];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    });
}

- (void)pushAppOintmentsForVisit {
    WEAKSELF
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        HJAppointmentsController*vc=[[HJAppointmentsController alloc] initWithIndex:0];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    });
}

@end
